package ui.student_ui;

import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.EmptyBorder;

import ui.component.FontPack;
import vo.CourseVO;

@SuppressWarnings("serial")
public class CourseInformationPanel extends JPanel {
	private StudentPicPath path = new StudentPicPath();
	private JTextArea outline;
	private JScrollPane outlinePane;
	private JTextArea textbook;
	private JScrollPane textbookPane;
	private JTextArea reference;
	private JScrollPane referencePane;
//	[x=104,y=240][x=380,y=540]
	private Rectangle outlineRect = new Rectangle(114,2560, 360 - 104 , 520 - 240);
//	[x=378,y=240][x=594,y=540]
	private Rectangle textbookRect = new Rectangle(378,260 , 594 - 378, 520 - 240);
//	[x=598,y=239]t[x=863,y=538]
	private Rectangle referenceRect = new Rectangle(598 , 260, 843-598, 520-240);
	public CourseInformationPanel(){
		this.setLayout(null);
		this.setBorder(new EmptyBorder(0,10,0,10));
		initOutline();
		initTextbook();
		initReference();
		this.add(outlinePane);
		this.add(textbookPane);
		this.add(referencePane);
	}
	public void setCourse(CourseVO course){
		setCourse(course.getCourseOutline(),course.getTextbook(),course.getReferenceBook());
	}
	public void setCourse(String ol,String tb, String rf){
		this.outline.setText(ol);
		this.textbook.setText(tb);
		this.reference.setText(rf);
//		System.out.println(ol);
		this.repaint();
	}
	private void setFont(JTextArea text){
		text.setFont(FontPack.getCourseInfoFont(25));
	}
	private JScrollPane createScrollPane(JTextArea text,Rectangle rect){
		JScrollPane scroll = new JScrollPane();
		scroll.setBounds(rect);
		scroll.setBorder(new EmptyBorder(0,0,0,0));
		scroll.getViewport().setOpaque(false);
		scroll.setOpaque(false);
		scroll.setViewportView(text);
		return scroll;
	}
	private void initOutline(){
		outline = new JTextArea(10,15);
		setFont(outline);
		outline.setLineWrap(true);
		outline.setBorder(new EmptyBorder(0,0,0,0));
		outline.setEditable(false);
		
		outlinePane = createScrollPane(outline,outlineRect);
	}
	private void initTextbook(){
		textbook = new JTextArea(10,15);
		textbook.setLineWrap(true);
		setFont(textbook);
		textbook.setBorder(new EmptyBorder(0,0,0,0));
		textbook.setEditable(false);
		
		textbookPane = createScrollPane(textbook,textbookRect);
	}
	private void initReference(){
		reference = new JTextArea(10,15);
		reference.setLineWrap(true);
		setFont(reference);
		reference.setBorder(new EmptyBorder(0,0,0,0));
		reference.setEditable(false);
		
		referencePane = createScrollPane(reference,referenceRect);
	}
	@Override 
	protected void paintComponent(Graphics g){
		super.paintComponent(g);
		BufferedImage im = null;
		try {
			 im = ImageIO.read(new File(path.getCourseInfo()));
		} catch (IOException e) {
			e.printStackTrace();
		}
		g.drawImage(im, 0, 0,this.getWidth(),this.getHeight(), null);
	}
}
